package com.ruoyi.ice.domain;

import com.ice.core.annotation.IceNode;
import com.ice.core.context.IceRoam;
import com.ice.core.leaf.roam.BaseLeafRoamFlow;
import com.ruoyi.common.utils.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;

@Data
@EqualsAndHashCode(callSuper = true)
@IceNode(name = "数值探针节点", desc = "用于探测roam中的数字是否大于等于目标数值")
public class ScoreFlow extends BaseLeafRoamFlow {

    private BigDecimal score;

    private String key;

    @Override
    protected boolean doRoamFlow(IceRoam roam) {

        Object value = roam.getMulti(key);

        if (value == null) {
            return false;
        }

        if(StringUtils.isNull(score))
            return false;

        BigDecimal valueScore = new BigDecimal(String.valueOf(value));

        return !(valueScore .compareTo(score) == -1 );
    }
}
